package com.yykt.weshare.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yykt.weshare.Exception.AppException;
import com.yykt.weshare.entity.Users;
import com.yykt.weshare.enums.ResultEnum;
import com.yykt.weshare.mapper.UsersMapper;
import com.yykt.weshare.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 93474
* @description 针对表【yykt_users(平台用户表)】的数据库操作Service实现
* @createDate 2024-07-14 19:25:43
*/
@Service
public class UsersServiceImpl implements UsersService{

    @Autowired
    UsersMapper usersMapper;

    @Override
    public Users checkLogin(String username, String password) {
        Users user = usersMapper.findOneByUsernameAndPassword(username, password);
        if (user == null) {
            throw new AppException(ResultEnum.USERNAME_PASSWORD_ERROR);
        }
        return user;
    }

    public PageInfo<Users> findALL(String username, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy("num desc, status asc");
        List<Users> all = usersMapper.findALL(username);
        return new PageInfo<>(all);
    }
}




